class PhoneValidator < ActiveModel::EachValidator
  def validate_each(record,attribute,value)
    begin
      n_digits = value.scan(/[0-9]/).size
      valid_chars = (value =~ /^[+\/\-() 0-9]+$/)
      r = (n_digits == 11) 
      r &&= valid_chars
    rescue Exception => e   
      r = false
    end
    record.errors[attribute] << (options[:message] || "is invalid") unless r
  end
end